package com.bike.bikeserver.controller.frontend;

import com.bike.bikeserver.common.annotation.OperationLog;
import com.bike.bikeserver.common.core.domain.CommonResult;
import com.bike.bikeserver.domain.WXUser;
import com.bike.bikeserver.service.IWXUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @version 1.0
 * @Author ZZX
 * @Date 2023/7/8 17:42
 */
@RestController
@RequestMapping("front/wxuser")
public class WXUserController
{
    @Autowired
    IWXUserService wxUserService;

    /**
     * 用户登录
     *
     * @param wxUser
     * @return
     */
    @PostMapping("login")
    @OperationLog(value = "微信用户登录:wxuser")
    public CommonResult wxuserLogin(@RequestBody WXUser wxUser)
    {
        return wxUserService.wxuserLogin(wxUser);
    }

    /**
     * 用户注销
     *
     * @param nickName
     * @return
     */
    @GetMapping("logout")
    @OperationLog(value = "微信用户注销:wxuser")
    public CommonResult wxuserLogout(@RequestParam("nickName") String nickName)
    {
        return wxUserService.wxuserLogout(nickName);
    }

    /**
     * 检测特定用户的jwt是否已经失效
     *
     * @return
     */
    @GetMapping("monitorJWT")
    public CommonResult monitorJWT()
    {
        return CommonResult.success("用于检测特定用户的jwt是否已经失效，如果已经失效，此请求会被拦截，并给前端返回与token有关的msg");
    }

    /**
     * 根据用户名获取用户类型：普通用户、工作人员
     *
     * @param nickName
     * @return
     */
    @OperationLog(value = "根据微信用户名获取用户类型:wxuser")
    @GetMapping("getUserTypeByNickName")
    public CommonResult getUserTypeByNickName(@RequestParam("nickName") String nickName)
    {
        return wxUserService.getUserTypeByNickName(nickName);
    }

    /**
     * 根据用户名获取其加入时间、天数、积分和优惠券总数
     *
     * @param nickName
     * @return
     */
    @OperationLog(value = "根据微信用户名获取其加入时间、天数、积分和优惠券总数:wxuser")
    @GetMapping("getJoinTimeByNickName")
    public CommonResult getJoinTimeByNickName(@RequestParam("nickName") String nickName)
    {
        return wxUserService.getJoinTimeByNickName(nickName);
    }
}